package com.shine.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.shine.app.AppManager;
import com.shine.app.BaseActivity;
import com.shine.app.R;
import com.shine.app.inject.InjectView;
import com.shine.app.inject.Injector;

public class LocationOpenGpsDialogActivity extends BaseActivity implements
		OnClickListener {

	@InjectView(R.id.submit)
	private TextView submiTextView;
	@InjectView(R.id.cancel)
	private TextView cancelTextView;
	@InjectView(R.id.message)
	private TextView messageTextView;
	@InjectView(R.id.layout)
	private LinearLayout layout;
	@InjectView(R.id.progressBar)
	private ProgressBar progressBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.dialog_cancelteetimes);
		Injector.get(this).inject();

		init();
	}

	private void init() {
		progressBar.setVisibility(View.GONE);
		cancelTextView.setText(R.string.dialog_no);
		submiTextView.setText(R.string.dialog_yes);
		messageTextView.setText(R.string.msg_location_services_open);
		submiTextView.setOnClickListener(this);
		cancelTextView.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.cancel:
			AppManager.getAppManager().finishActivity();
			break;
		case R.id.submit:
			Intent intent = new Intent();
			intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			this.startActivity(intent);
			AppManager.getAppManager().finishActivity();
			break;

		default:
			break;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			AppManager.getAppManager().finishActivity();
		}
		return super.onKeyDown(keyCode, event);
	}
}
